/*JavaScript语言面向过程编程方式*/
window.onload = function(){
    /*校验用户是否存在*/
    $("#emailAddress").blur(function () {
        /*不为空时提交数据*/
        if($("#emailAddress").val() != ""){
            var exp = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
            if(exp.test($("#emailAddress").val())){
                $.ajax({
                    /*请求地址*/
                    url:"isExitsUser.ax",
                    /*请求方式*/
                    type:"POST",
                    /*携带数据*/
                    data:{
                        email:$("#emailAddress").val()
                    },
                    success:function (resp) {
                        if(resp == "exits"){
                            $("#tips").attr("style","font-family:方正小标宋简体;color:red;FONT-SIZE: 10pt");
                            $("#btn").attr("disabled",true);
                            $("#tips").text("用户存在,请重新输入");
                        }
                        else{
                            $("#tips").attr("style","font-family:方正小标宋简体;color:green;FONT-SIZE: 10pt");
                            $("#btn").attr("disabled",false);
                            $("#tips").text("当前邮箱合法");
                        }
                    }
                })
            }
            else {
                alert("邮箱格式非法~")
            }
        }
    })
    /*输入合法性校验*/
    document.getElementById("btn").onclick = function () {
        var firstName = document.getElementById("fName").value;
        var lastName = document.getElementById("lName").value;
        var emailAddress = document.getElementById("emailAddress").value;
        var tel = document.getElementById("tel").value;
        var password = document.getElementById("password").value;
        var confirmPassword = document.getElementById("confirmPassword").value;
        if(firstName == "" || lastName == "" || emailAddress == "" || password == "" || confirmPassword == "" || tel == ""){
                alert("输入不能为空！");
                return;
        }
        else{
            if(password != confirmPassword){
                document.getElementById("password").focus();
                alert("密码输入不一致!");
                return;
            }
            document.forms["userReg"].submit();
        }
    }
}
